package com.ljs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class TestOracle {
    private static String url="jdbc:oracle:thin:@localhost:1521:ljs";
    private static  String driver="oracle.jdbc.driver.OracleDriver";

    private static String username="system";
    private static String password="Ljs123456";
    private static Connection conn=null;

    static{
        try {
            Class.forName(driver);

        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static Connection getConnection(){

        try {
            if(conn==null||conn.isClosed()){
                conn= DriverManager.getConnection(url, username, password);

            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return conn;
    }

    public static void close(Connection conn){
        try {

            if(conn!=null||!conn.isClosed()){
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        System.out.println(getConnection());
    }
}
